<template class="body">
  <van-row class="main-menu">
    <div class="tablecontent">
      <!-- 单位考评 -->
      <el-table
        v-loading="loading"
        @row-click="doShowDetail"
        :data="scorpdata"
        stripe
        v-if="this.assessType === this.$vo.AssessType.CORP + '' ? false : true"
        style="width: 100%;margin-top:30px;display: inline-block;"
      >
        <template slot="empty">
          <van-empty v-if="scorpdata.length === 0" description="暂无数据" />
        </template>
        <el-table-column prop="deptName" label="部门名称" width="250">
        </el-table-column>
        <el-table-column prop="total" label="总分">
        </el-table-column>
        <el-table-column prop="upTotal" label="上半年总分">
        </el-table-column>
        <el-table-column prop="upAdd" label="上半年加分">
        </el-table-column>
        <el-table-column prop="upSub" label="上半年减分">
        </el-table-column>
        <el-table-column prop="downTotal" label="下半年总分">
        </el-table-column>
        <el-table-column prop="downAdd" label="下半年加分">
        </el-table-column>
        <el-table-column prop="downSub" label="下半年减分">
        </el-table-column>
      </el-table>
      <!-- 公司考评 -->
      <el-table
        v-loading="loading"
        :data="scorpdata"
        stripe
        v-if="this.assessType === this.$vo.AssessType.CORP + '' ? true : false"
        style="width: 100%;margin-top:30px;display: inline-block;"
      >
        <template slot="empty">
          <van-empty v-if="scorpdata.length === 0" description="暂无数据" />
        </template>
        <el-table-column prop="deptName" label="部门名称" width="150">
        </el-table-column>
        <el-table-column prop="total" label="总分" >
          <template slot-scope="scope">
            <span class="clickbtn" @click="totalZongfen(scope.row,0)">{{scope.row.total}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="upTotal" label="上半年总分">
          <template slot-scope="scope">
            <span class="clickbtn" @click="totalZongfen(scope.row,1)">{{scope.row.upTotal}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="upAdd" label="上半年加分">
        </el-table-column>
        <el-table-column prop="upSub" label="上半年减分">
        </el-table-column>
        <el-table-column prop="downTotal" label="下半年总分">
          <template slot-scope="scope">
            <span class="clickbtn" @click="totalZongfen(scope.row,2)">{{scope.row.downTotal}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="downAdd" label="下半年加分">
        </el-table-column>
        <el-table-column prop="downSub" label="下半年减分">
        </el-table-column>
      </el-table>

      <!-- 公司考评二层 -->
      <div id="chendin">
        <el-dialog
          :visible.sync="gssubdialogVisible"
          :show-close="false"
          v-if="this.assessType === this.$vo.AssessType.CORP + '' ? true : false"
          width="100%"
          height="100%"
        >
        <div class="topclose" @click="gssubdialogVisible = false">返回</div>  
          <div class="tablecontent xiaochu">
            <el-table
              v-loading="loading"
              :data="gssubData"
              stripe
              style="width: 100%;margin-top:30px;"
            >
        <template slot="empty">
          <van-empty v-if="gssubData.length === 0" description="暂无数据" />
        </template>
        <el-table-column prop="auditDept" label="部门名称" width="150">
        </el-table-column>
        <el-table-column prop="total" label="总分" >
        </el-table-column>
        <el-table-column prop="upTotal" label="上半年总分">
        </el-table-column>
        <el-table-column prop="upAdd" label="上半年加分">
          <template slot-scope="scope">
            <span class="clickbtn" @click="shangxiaZongfen(scope.row,1,1)">{{scope.row.upAdd}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="upSub" label="上半年减分">
          <template slot-scope="scope">
            <span class="clickbtn" @click.stop="shangxiaZongfen(scope.row,1,0)">{{scope.row.upSub}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="downTotal" label="下半年总分">
        </el-table-column>
        <el-table-column prop="downAdd" label="下半年加分">
          <template slot-scope="scope">
            <span class="clickbtn" @click.stop="shangxiaZongfen(scope.row,2,1)">{{scope.row.downAdd}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="downSub" label="下半年减分">
          <template slot-scope="scope">
            <span class="clickbtn" @click.stop="shangxiaZongfen(scope.row,2,0)">{{scope.row.downSub}}</span>
          </template>
        </el-table-column>
            </el-table>
            <!-- <div class="pagefanye right">
              <el-pagination
                @size-change="handleSizeChangePinfen"
                @current-change="handleCurrentChangePinfen"
                :current-page="currentPage"
                :page-sizes="[5, 10, 20, 40]"
                :page-size="pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="subData.length"
              >
              </el-pagination>
           </div> -->
          </div>
        </el-dialog>
      </div>

      <!-- 公司单位扣分加分 -->
      <div id="chendin">
        <el-dialog
          :visible.sync="subdialogVisible"
          :show-close="false"
          width="100%"
          height="100%"
        >
        <div class="topclose" @click.stop="subdialogVisible = false">返回</div>
        <!-- <div class="demo-input-suffix inputbox">
          评分人：
          <el-input
            placeholder="请输入内容"
            v-model="pfr">
          </el-input>
        </div>
        <div class="demo-input-suffix inputbox">
          评分部门：
          <el-select
            clearable
            v-model="pfbm"
            placeholder="请选择"
            filterable
            allow-create
          >
            <el-option
              v-for="(item, i) in options.dwmc"
              :key="i"
              :value="item"
              :label="item"
            ></el-option>
          </el-select>
        </div>
        <div class="inputbox demo-input-suffix">
          <el-button
            @click="repaly"
            >重置</el-button
          >
        </div>
        <div class="inputbox demo-input-suffix">
          <el-button
            type="primary"
            @click="getwtDatalist"
            icon="el-icon-search"
            >查询</el-button
          >
        </div> -->
          <div class="tablecontent xiaochu">
            <!-- 单位各部门扣分加分 -->
            <el-table
              v-loading="loading"
              @row-click="doShowdialog"
              v-if="this.assessType === this.$vo.AssessType.CORP + '' ? false : true"
              :data="subData.slice(
                        (currentPage - 1) * pagesize,
                        currentPage * pagesize
                      )"
              stripe
              style="width: 100%;margin-top:30px;"
            >
              <template slot="empty">
                <van-empty v-if="subData.length === 0" description="暂无数据" />
              </template>
              <el-table-column prop="title" label="标题" width="300">
              </el-table-column>
              <el-table-column prop="khbm" label="评分部门">
              </el-table-column>
              <el-table-column prop="bmmc" label="部门名称">
              </el-table-column>
              <el-table-column prop="score" label="评分">
              </el-table-column>
              <el-table-column prop="username" label="评分人">
              </el-table-column>
              <el-table-column prop="grade_time" label="评分时间">
              </el-table-column>
            </el-table>
            <!-- 公司各部门扣分加分 -->
            <el-table
              v-loading="loading"
              @row-click="doShowdialog"
              v-if="this.assessType === this.$vo.AssessType.CORP + '' ? true : false"
              :data="gssubDatathree.slice(
                        (currentPage - 1) * pagesize,
                        currentPage * pagesize
                      )"
              stripe
              style="width: 100%;margin-top:30px;"
            >
              <template slot="empty">
                <van-empty v-if="gssubDatathree.length === 0" description="暂无数据" />
              </template>
              <el-table-column prop="title" label="标题" width="300">
              </el-table-column>
              <el-table-column prop="khbm" label="评分部门">
              </el-table-column>
              <el-table-column prop="bmmc" label="部门名称">
              </el-table-column>
              <el-table-column prop="score" label="评分">
              </el-table-column>
              <el-table-column prop="username" label="评分人">
              </el-table-column>
              <el-table-column prop="grade_time" label="评分时间">
              </el-table-column>
            </el-table>
            <div class="pagefanye right">
              <el-pagination
                @size-change="handleSizeChangePinfen"
                @current-change="handleCurrentChangePinfen"
                :current-page="currentPage"
                :page-sizes="[5, 10, 20, 40]"
                :page-size="pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="subData.length"
              >
              </el-pagination>
           </div>
          </div>
        </el-dialog>
      </div>
      <!-- 整改 -->
      <div style="z-index: 3002;">
        <van-popup
          v-model="showPageRectifyDetail"
          position="right"
          get-container="body"
          style="width: 100%; height: 100%; background-color: #F9F9F9">
          <dealt-with-detail v-if="showPageRectifyDetail" :rectify="selectedRectify" @onCancel="showPageRectifyDetail = false ,subdialogVisible = true" @onConfirm="doConfirm"/>
        </van-popup>
        <!-- 评分 -->
        <van-popup
          v-model="showPageGradeDetail"
          position="right"
          get-container="body"
          style="width: 100%; height: 100%; background-color: #F9F9F9">
          <dealt-with-pfdetail v-if="showPageGradeDetail" :grade="selectedGrade" @onCancel="showPageGradeDetail = false ,subdialogVisible = true,gssubdialogVisible = true" @onConfirm="doConfirm"/>
        </van-popup>
        <!-- 加分 -->
        <van-popup
          v-model="showPageRaiseDetail"
          position="right"
          get-container="body"
          style="width: 100%; height: 100%; background-color: #F9F9F9">
          <dealt-with-sub v-if="showPageRaiseDetail" :apply="selectApply" v-on:onCancel="showPageRaiseDetail = false ,subdialogVisible = true,gssubdialogVisible = true " @onConfirm="doConfirm"/>
        </van-popup>
      </div>
    </div>
  </van-row>
</template>

<script>
import DealtWithDetail from '@/views/dealtwith/DealtWithDetail' //整改详情
import DealtWithPfdetail from '@/views/dealtwith/DealtWithPfdetail' //评分详情
import DealtWithSub from '@/views/dealtwith/DealtWithSub' //加分详情
import { scoreDwDetailedList,scoreGsDetailedList,scoreDeptList,QuestionDetails,selectDetailedTotalList  } from "../../api/dealtwith";
// import PanelRectifyBaseInfo from '@/views/rectify/common/panel/PanelRectifyBaseInfo'
export default {
  name: 'ScorePingList',
  // components: { PanelRectifyBaseInfo,PanelHistoryProcess},
  components: { DealtWithDetail,DealtWithPfdetail,DealtWithSub },
  props:{
     scorpdata:Array,
     assessType:String,
     year:String,

  },
  watch:{
    scorpdata(val){
      this.scorpdata = val
    }
  },
  computed: {

  },
  created(){
    // this.department_name = this.$store.state.authInfo.user.rectify[0].department_path; 
  },
  mounted(){
    // this.department_name= this.department_name.split('/')
    // console.log(this.department_name)
    console.log(this.assessType)
  },
  data(){
    return{
      currentPage: 1, //初始页
      pagesize: 10, // 每页的数据
        wentiData: [

      ],
      department_name:[],
      subdialogVisible: false, 
      gssubdialogVisible:false,
      subData: [],
      gssubData:[],
      gssubDatathree:[],
      loading: false,//加载
      options: {
        //下拉框 选项
        dwmc: [], //单位名称
      },
      pfbm:'',
      pfr:'',
      deptName:'',
      gsdeptName:'',
      showPageRectifyDetail: false, //整改详情
      showPageGradeDetail: false,  //评分详情
      showPageRaiseDetail: false,  //加分详情
    }
  },
  methods:{
    //重置
    repaly(){
      this.pfbm= "",
      this.pfr= ""
    },
    getwtDatalist(){
      this.loading = true
      if(this.assessType === this.$vo.AssessType.CORP){
        scoreGsDetailedList({ username:this.pfr,year:this.year,bmmc:this.deptName,check_type:this.assessType === this.$vo.AssessType.CORP + '' ? 0 : 1,khbm:this.pfbm})
        .then((res) => {
          console.log(res);
        this.loading = false
          this.subdialogVisible = true;
          this.subData = res.data.retData;

        })
        .catch((err) => {
          this.loading = false;
          console.log("报错！！！！！！！！！！！");
        });
      }else{
        scoreDwDetailedList({ username:this.pfr,year:this.year,bmmc:this.deptName,check_type:this.assessType === this.$vo.AssessType.CORP + '' ? 0 : 1,khbm:this.pfbm})
        .then((res) => {
          console.log(res);
        this.loading = false
          this.subdialogVisible = true;
          this.subData = res.data.retData;

        })
        .catch((err) => {
          this.loading = false;
          console.log("报错！！！！！！！！！！！");
        });
        }

    },
    doShowDetail (row) {
      this.loading = true
      this.deptName = row.deptName
      console.log(row)
      scoreDwDetailedList({ username:'',year:this.year,bmmc:row.deptName,check_type:this.assessType === this.$vo.AssessType.CORP + '' ? 0 : 1,khbm:''})
      .then((res) => {
        console.log(res);
        this.loading = false
        this.subdialogVisible = true;
        this.subData = res.data.retData;
      })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
      scoreDeptList({year:this.year,type:this.assessType === this.$vo.AssessType.CORP + '' ? 0 : 1,bmmc:row.deptName })
        .then((res) => {
          console.log(res);
          this.options.dwmc = res.data.retData;
        })
        .catch((err) => {
          this.loading = false;
          console.log("报错！！！！！！！！！！！");
      });
    },
    doShowdialog(row){
    console.log(row)
      //       showPageRectifyDetail: false, //整改详情
      // showPageGradeDetail: false,  //评分详情
      // showPageRaiseDetail: false,  //加分详情
      this.loading = true
      QuestionDetails({checkType:row.check_type +'',objType:row.type + '',problemId:row.id })
      .then((res) => {
        console.log(res);
      this.loading = false
        if(row.type == 0){
          if(this.assessType === this.$vo.AssessType.CORP + ''){
            this.gssubdialogVisible = false
          }
          this.showPageGradeDetail= true  //评分详情
          this.subdialogVisible = false
          this.selectedGrade = res.data.retData
        }else if(row.type == 1){
          if(this.assessType === this.$vo.AssessType.CORP + ''){
            this.gssubdialogVisible = false
          }
          this.showPageRaiseDetail= true  //加分详情
          this.subdialogVisible = false
          this.selectApply = res.data.retData
        }
      })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    //公司考评总分二层
    totalZongfen(row,index){
      this.gsdeptName = row.dwmc
      console.log(index)
      this.loading = true;
      selectDetailedTotalList({year:this.year,time_type:index,dwmc:row.deptName  })
      .then((res) => {
        console.log(res);
        this.loading = false
        this.gssubdialogVisible = true;
        this.gssubData = res.data.retData;
      })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    //公司考评三层
    shangxiaZongfen(row,TIME_TYPE,SCORE_TYPE){
      console.log(TIME_TYPE)
      console.log(SCORE_TYPE)
      this.loading = true;
      scoreGsDetailedList({khbm:row.auditDept,year:this.year,time_type:TIME_TYPE,score_type:SCORE_TYPE,bmmc:this.gsdeptName})
      .then((res) => {
        console.log(res);
        this.loading = false
        this.subdialogVisible = true;
        this.gssubDatathree = res.data.retData;
      })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    doConfirm () {
      this.showPageRectifyDetail = false
    },
    handleSizeChangeWenti(val) {
      this.pagesize = val;
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChangeWenti(val) {
      this.currentPage = val;
      console.log(`当前页: ${val}`);
    },
    handleSizeChangePinfen(val) {
      this.pagesize = val;
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChangePinfen(val) {
      this.currentPage = val;
      console.log(`当前页: ${val}`);
    },
  }


}
</script>

<style scoped lang="less">
/deep/.el-input {
  width:unset;
}
.demo-input-suffix{
  display: inline-block;
  margin-right: 10px;
  margin-bottom: 10px;
}
/deep/.el-dialog {
  height: 100%;
  margin: 0!important;
  }
.topclose{
  position: absolute;
  top: 16px;
  left: 16px;
  color: #1989fa;
  cursor: pointer;
}
/deep/.cell {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    height: 42.4px;
  }
  .pagefanye {
    margin-top: 10px;
}
.right {
    float: right;
}
.el-pagination{
  white-space: normal;
  white-space: nowrap;
  padding: 2px 5px 10px 5px;
  color: #303133;
  font-weight: 700;
}
/deep/.el-dialog__wrapper{
  background: white;
  overflow-y:auto;
}
span.clickbtn {
  width: 100%;
  height: 100%;
  display: inline-block;
  color: red;
}
</style>
